//
//  StarsView.m
//  C20_UI-zuoye(1)
//
//  Created by GeminyXC on 15-3-14.
//  Copyright (c) 2015年 lanou3g.com. All rights reserved.
//

#import "StarsView.h"

@implementation StarsView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

////不自定义初始化了?不可以
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        for (NSInteger i = 0; i < 5; i ++) {
            self.imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(i * self.frame.size.width / 5, 0, self.frame.size.width / 5, self.frame.size.height)];
            [self addSubview:_imageView1];
            [_imageView1 release];
        }
        
//        self.ratLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width * 5 / 7, 0, self.frame.size.width * 2 / 7, self.frame.size.height)];
//        self.ratLabel.text = @"评分";
//        [self addSubview:_ratLabel];
//        [_ratLabel release];
//        

    }
    return self;
}

//- (void)getWithStars:(NSString *)stars rating:(NSNumber *)rating
- (void)getWithStars:(NSString *)stars
{
    //将nsstring转为NSInteger
    NSInteger starss = [stars integerValue];
    
    //将nsnumber转为cgfloat
//    CGFloat ratingg = [rating floatValue];
    
    NSInteger st1 = starss / 10;
    NSInteger st2 = (starss % 10) / 5;
    //        NSInteger st3 = 5 - (st1 + st2);
    
    for (NSInteger i = 0; i < 5; i++) {
        if (i < st1) { //写成 i <= i < 2 ,下面写成2 <= i < 3,怎么就不行呢,连着写不行?复习!
            UIImageView *view1 = [self.subviews objectAtIndex:i];//这里用属性也应该可以
            view1.image = [UIImage imageNamed:@"star1.png"];
        }else if ((i <= st1) && (i < (st1 + st2))){
            UIImageView *view2 = [self.subviews objectAtIndex:i];
            view2.image = [UIImage imageNamed:@"star2.png"];
        }else{
            UIImageView *view3 = [self.subviews objectAtIndex:i];
            view3.image = [UIImage imageNamed:@"star3.png"];
        }
    }
    
//    self.ratLabel.text = [NSString stringWithFormat:@"%.1f", ratingg];
    

}



@end
